package com.bruce.pattern.creational.prototype.clone;

import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * Created by bruce on 2018/11/3 15:47
 */
@Setter
@Getter
public class Pig2 implements Cloneable {
    private String name;

    private Date birthday;

    public Pig2(String name, Date birthday) {
        this.name = name;
        this.birthday = birthday;
    }

    @Override
    public Pig2 clone() throws CloneNotSupportedException {
        //深克隆,引用对象应该也要被克隆
        Pig2 pig = (Pig2) super.clone();
        Date date = (Date)pig.birthday.clone();

        pig.setBirthday(date);
        return pig;
    }
}
